﻿using System.Collections.Generic;
using System.IO;

namespace FemtoHttpd
{
    public class SimpleResponse : FemtoHttpResponse
    {
        public string Body { get; set; } = string.Empty;
        /// <summary>
        /// Send Data if Data is not null
        /// </summary>
        public byte[] Data { get; set; }

        private void BeginData()
        {
            Data = Data ?? ContentEncoding.GetBytes(Body);
        }

        public SimpleResponse(Stream output) : base(output)
        {
            
        }
        public override void CheckHeader(Dictionary<string, string> header)
        {
            BeginData();
            header["Content-Length"] = $"{Data.Length}";
            base.CheckHeader(header);
        }
        protected override void WriteContent()
        {
            Output.Write(Data, 0, Data.Length);
        }
    }
}
